#define paginate(currentPage, totalPage, link)
#if(totalPage <= 0 || currentPage > totalPage) #return #end
#setLocal(startPage = currentPage - 4)
#if (startPage < 1) #setLocal(startPage = 1) #end

#setLocal(endPage = currentPage + 4)
#if (endPage > totalPage) #setLocal(endPage = totalPage) #end

<div class="pagination">
    #if (currentPage <= 8)
    #setLocal(startPage = 1)
    #end
    #if ((totalPage - currentPage) < 8)
    #setLocal(endPage = totalPage)
    #end

    #if (currentPage == 1)
    <span class="disabled prev_page">上页</span>
    #else
    <a class="prev_page" href="#(link)#(currentPage - 1)#(append)">上页</a>
    #end

    #if (currentPage > 8)
    <a href="#(link)#(1)#(append)">#(1)</a>
    <a href="#(link)#(2)#(append)">#(2)</a>
    <span class="gap">…</span>
    #end

    #for(i : [startPage..endPage])
    #if (currentPage == i)
    <span class="current">#(i)</span>
    #else
    <a href="#(link)#(i)#(append)">#(i)</a>
    #end
    #end

    #if ((totalPage - currentPage) >= 8)
    <span class="gap">…</span>
    <a href="#(link)#(totalPage - 1)#(append)">#(totalPage - 1)</a>
    <a href="#(link)#(totalPage)#(append)">#(totalPage)</a>
    #end

    #if (currentPage == totalPage)
    <span class="disabled next_page">下页</span>
    #else
    <a class="next_page" href="#(link)#(currentPage + 1)#(append)" rel="next">下页</a>
    #end
</div>
#end